package com.liang.crawlerwebmagic.test;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

public class JobProcessor implements PageProcessor {

    private Site site=Site.me();

    //负责解析页面
    @Override
    public void process(Page page) {

        //解析返回的数据page,并且把解析的结果放到ResultItems中
        page.putField("div",page.getHtml().css("div._2Kb8-nplK47lBDl_iifFWM").all());

        //XPath
        page.putField("div2",page.getHtml().xpath("//div[@]"));
    }

    @Override
    public Site getSite() {
        return site;
    }

    //主函数执行爬虫
    public static void main(String[] args) {
        Spider.create(new JobProcessor())
                .addUrl("https://kuaibao.jd.com/?ids=250489705,248908101,253499812,246420325")
                .run();//执行爬虫
    }
}
